<template>
  <div class="mod-config">
    <basic-container>
      <el-divider content-position="left">查询条件</el-divider>
      <el-form inline size="mini" label-width="80px">
        <el-form-item label="商品类别">
          <el-select v-model="dataForm.ctgId" clearable>
            <el-option v-for="item in ctgOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="退货审核日期">
            <el-col :span="11">
                <el-date-picker type="date" placeholder="选择日期" v-model="dataForm.createTimeStart" value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker>
            </el-col>
            <el-col class="line" :span="2" style="text-align: center;">至</el-col>
            <el-col :span="11">
                <el-date-picker type="date" placeholder="选择日期" v-model="dataForm.createTimeEnd" value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker>
            </el-col>
        </el-form-item>
        <!-- <el-form-item label="出库仓位" >
          <el-select v-model="dataForm.stockId" clearable>
            <el-option v-for="item in stockOptions" :value="item.id" :label="item.name" :key="item.id"></el-option>
          </el-select>
        </el-form-item> -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="出库仓位">
              <el-input size="mini" type="textarea" v-model="dataForm.outStockName" readonly>
              </el-input>
            </el-form-item>
            <el-form-item label-width="0">
              <el-button size="mini" @click="getStockList">选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row style="margin-top: 10px;">
          <el-form-item label-width="5px">
            <el-link  :href="printUrl" target="_blank" :disabled="isDisabled" type="primary"><el-button size="mini" type="primary" @click="getWorkParams">查 询</el-button></el-link>
          </el-form-item>
        </el-row>

      </el-form>
      <search-stock v-if="stockVisible" ref="stockInfo" @refreshData="getStockInfoList"></search-stock>
    </basic-container>
  </div>
</template>

<script>
  let params = ''
  import { filterParams } from '@/util/tools'
  import { getDateFormat } from '@/util/tools'
  import { mapGetters } from 'Vuex'
  import {getStockList,getStockInfo} from '@/api/eims/stock'
  import {getCtgList} from '@/api/eims/ctg'
  import searchStock from "@/components/business/stock-search"

  export default {
      data () {
        return {
          printUrl: '',
          stockVisible: false,
          dataForm: {
              ctgId: '',
              createTimeStart: '',
              createTimeEnd: '',
              stockId: '',
              outStockIds: [],
              outStockName: ''
          },
          isDisabled: true,
          ctgOptions: [],
          stockOptions: []
        };
      },
      computed: {
        ...mapGetters(['userInfo','bizData'])
      },
      components: {
        searchStock
      },
      created() {
        this.dataForm.createTimeStart = getDateFormat(new Date())
        this.dataForm.createTimeEnd = getDateFormat(new Date())
        this.findCtgList();
        this.getstockList();
        //this.getStockName();
      },
      methods:{
        getStockName(){
            let deptId = this.userInfo.lessDeptId
            getStockInfo(deptId).then(result=>{
                console.log(result.data.data[0].name);
                this.dataForm.stockId = result.data.data[0].name;
            })
        },
        getWorkParams() {
          this.isDisabled = true
          if(this.dataForm.outStockIds.length <=0){
            this.$message.warning('退货仓位不能为空')
            return false
          }
          this.isDisabled = false
          params = '/refundSummary.cpt'
          let data = filterParams(this.dataForm)
          let parameter = ''
          for(let key in data){
            parameter += '&' + key + '=' + this.dataForm[key]
          }
          //let parameter = '&deptId='+this.dataForm.deptId + '&beginTime='+this.dataForm.beginTime+ '&endTime='+this.dataForm.endTime
          this.printUrl = this.bizData.printUrl + params + parameter + '&op=view'
          
        },
       findCtgList(){
          getCtgList().then(result => {
            this.ctgOptions = result.data.data
          })
        },
        //  获取出库仓位列表
        getstockList() {
          getStockList().then(result => {
            this.stockOptions = result.data.data
          })
        },
        getStockList() {
          this.stockVisible = true;
          let data = [];
          if (this.dataForm.outStockIds) {
              data = this.dataForm.outStockIds;
          }
          this.$nextTick(() => {
            this.$refs.stockInfo.init(data);
          });
        },
        getStockInfoList(data) {
          this.dataForm.outStockIds = [];
          let name = "";
          data.forEach(result => {
            this.dataForm.outStockIds.push(result.id)
            name = name ? name + "," + result.name : result.name;
          });
          this.dataForm.outStockName = name
        },
      }
    }
</script>

<style lang="scss" scoped>
  .row-bg {
    background-color: #cadee8;
    // padding-left: 15px;
    padding-right: 15px;
    padding-top: 5px;
    margin-bottom: 2px;
  }
</style>
